-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patterns: show theme patterns from directory in site editor #55877
Conversation
Size Change: +2.12 kB (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
It might be worth noting that "remote" patterns or those from the pattern directory were deliberately omitted from the Site Editor's pattern page. If that decision is being reconsidered perhaps this should be labelled as |
Done. |
@@ -9,7 +9,6 @@ export const PATTERN_CORE_SOURCES = [ | |||
'core', | |||
'pattern-directory/core', | |||
'pattern-directory/featured', | |||
'pattern-directory/theme', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this makes the PATTERN_CORE_SOURCES
variable name no longer true, so perhaps the variable needs to be renamed as well (EXCLUDED_LIBRARY_SOURCES
?), or the filtering could be done a different way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it actually applies better now as previously it included theme specified patterns from the directory which are essentially theme patterns rather than core, now it is more strictly just core patterns that are not related to the current theme at all.
Having looked at the places where PATTERN_CORE_SOURCES
is currently used the name still seems to fit in the context - but happy to rename if you still think it is not a suitable name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @talldan on the naming here.
previously it included theme specified patterns from the directory which are essentially theme patterns rather than core
The source of the patterns is core and the pattern directory, not the theme. The theme doesn't create or define the patterns, it only "opts into" using them, which doesn't change their actual source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it confuses things to not think of these as theme patterns - from the user perspective they are a theme pattern regardless of the source, but I will try and come up with a name for the constant that better reflects the situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the user perspective they are a theme pattern regardless of the source
Luckily, we're referring to a variable name here that isn't exposed to users, so we can afford to be accurate.
We could also argue that for most users they only see patterns, not user, theme, or core patterns etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the new naming of NON_THEME_PATTERN_SOURCES
introduced in 316bc22 is any better than PATTERN_CORE_SOURCES
. As discussed, the source is still the pattern directory not the theme, so NON_THEME_PATTERN_SOURCES
should still include pattern-directory/theme
in my view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have renamed the constant to NON_THEME_PATTERN_SOURCES
, which makes the nature of it a bit clearer in the contexts it is used I think, eg.
const selectThemePatterns = createSelector(
...
.filter( ( pattern ) => ! NON_THEME_PATTERN_SOURCES.includes( pattern.source ))
...
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dan's suggested name EXCLUDED_LIBRARY_SOURCES
sidesteps most of the discussed issue by naming the array by its purpose. It might require an extra tweak to an inline comment and variable but that's neither here nor there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have updated that inline comment and variable
Flaky tests detected in 316bc22. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6792013570
|
return patterns | ||
.filter( | ||
filterOutCorePatterns && | ||
filterOutExcludedPatternSources && | ||
filterOutDuplicatesByName && | ||
filterCompatiblePatterns | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unusual that the functions aren't called here ... Is this a bug? I think it should be:
return patterns
.filter( ( pattern ) =>
filterOutExcludedPatternSources( pattern ) &&
filterOutDuplicatesByName( pattern ) &&
filterCompatiblePatterns( pattern )
)
Right now I'd expect it always evaluates to true
. If so, it's curious that there's not visible bug. Maybe the logic is duplicated, perhaps the call to filter can be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, well spotted. In my testing of this only the last method is called. I will put up a separate PR for this as will be easier to review/test in isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing well for me. I had to update to 6.4 to test.
I left a comment about an intriguing piece of code (the PR does touch the code, but the potential issue is already in trunk, so it doesn't need to be fixed in this PR).
What?
Shows theme patterns specified in theme.json in the site editor.
Why?
Currently patterns specified in the
patterns
section oftheme.json
display in the post editor site editor, but do not disply in the site editor patterns page.Fixes: #55819
How?
Removes
pattern-directory/theme
from thePATTERN_CORE_SOURCES
constant that is used to filter these patterns in the site editor.Testing Instructions
Testimonial
tab and make sure two patterns appear -Centered Terstimonial
andClients
Testimonial
category and make sure the same two patterns appearClients
pattern and make sure this works as expected and new pattern is usable/editableScreenshots or screencast
Before:
patterns-before.mp4
After:
patterns-after.mp4